package jjn.round1;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Jjn
 * @since 2022/10/3 23:22
 */
public class LeetCode784_LetterCasePermutation {
    public List<String> letterCasePermutation(String s) {
        List<String> result = new ArrayList<>();
        if (s == null) {
            return result;
        }
        backtrack(result, s.toCharArray(), 0);
        return result;
    }

    private void backtrack(List<String> result, char[] chars, int current) {
        if (current == chars.length) {
            result.add(new String(chars));
            return;
        }
        backtrack(result, chars, current + 1);
        if (Character.isLetter(chars[current])) {
            if (Character.isLowerCase(chars[current])) {
                chars[current] = Character.toUpperCase(chars[current]);
            } else {
                chars[current] = Character.toLowerCase(chars[current]);
            }
            backtrack(result, chars, current + 1);
        }
    }
}
